import wsgiref.handlers


from google.appengine.ext import webapp
from google.appengine.ext import db

from whrandom import choice
import string

def GenPasswd():
    chars = string.letters + string.digits
    for i in range(8):
        newpasswd = newpasswd + choice(chars)
    return newpasswd


class NewGroupHandler(webapp.RequestHandler):
  def post(self):
	group = Group();
	group.name = self.request.get('groupName')
	group.email = self.request.get('emailAddress')
	group.password = GenPasswd()
	if group.put():
		template_values = {
		      'groupName': group.name
		}
		path = os.path.join(os.path.dirname(__file__), 'created.html')
	    self.response.out.write(template.render(path))
	else:
	  self.redirect('/')
	 


def main():
  application = webapp.WSGIApplication( [('/group/new', NewGroupHandler)], debug=True)
  wsgiref.handlers.CGIHandler().run(application)


if __name__ == '__main__':
  main()
